#!/bin/bash

# 配置系统测试脚本
echo "=== 配置系统测试 ==="
echo ""

# 1. 测试默认配置
echo "1. 测试默认配置..."
make config-validate
echo ""

# 2. 测试环境变量覆盖
echo "2. 测试环境变量覆盖..."
echo "设置测试环境变量..."
export DB_HOST=test-mysql
export DB_PORT=3307
export DB_USER=test_user
export DB_PASSWORD=test_password
export DB_NAME=test_db

echo "验证环境变量覆盖效果..."
go run cmd/config-tool/main.go -action=show | grep -A 10 "Database:"
echo ""

# 3. 测试 Viper 环境变量
echo "3. 测试 Viper 环境变量..."
export LEARN_GO_DEMO_APP_ENVIRONMENT=test
export LEARN_GO_DEMO_APP_LOG_LEVEL=debug
export LEARN_GO_DEMO_GRPC_PORT=50099
export LEARN_GO_DEMO_HTTP_PORT=8099

echo "验证 Viper 环境变量效果..."
go run cmd/config-tool/main.go -action=show | grep -A 5 "Application:"
go run cmd/config-tool/main.go -action=show | grep -A 5 "Services:"
echo ""

# 4. 清理环境变量
echo "4. 清理测试环境变量..."
unset DB_HOST DB_PORT DB_USER DB_PASSWORD DB_NAME
unset LEARN_GO_DEMO_APP_ENVIRONMENT LEARN_GO_DEMO_APP_LOG_LEVEL
unset LEARN_GO_DEMO_GRPC_PORT LEARN_GO_DEMO_HTTP_PORT

echo "验证清理后的配置..."
make config-validate
echo ""

echo "✅ 配置系统测试完成！"
echo ""
echo "💡 提示："
echo "  - 配置文件位置: configs/"
echo "  - 环境变量前缀: LEARN_GO_DEMO_"
echo "  - 敏感信息环境变量: DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME"
echo "  - 配置文档: docs/CONFIGURATION.md"
